<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core " %>
<%@include file="./../../../taglibs.jsp"%>
<html>
<head>
    <%@include file="./../../../header.jsp"%>
</head>

	<body class="body">
		<input type="hidden" name="jsid" value="" />
		<div class="section">
			<div class="wrapper-md">
	       		<h1 class="fl" id="title">权限管理</h1>
	       		<div class="fr">
	       			<div class="def-btn-group">
	       				<button class="def-btn def-btn-primary" onclick="save()"><i class="gopng gopng_page"></i> 保存</button>
	       			</div>
	       		</div>
	        </div>

			<div class="section-content">
				<div class="dtree">
					<p>
						<a href="javascript:d.closeAll();">展开</a> 
						| 
						<a href="javascript:d.openAll();">折叠</a>
					</p>
					<div id="dtree_wrapper">
						
					</div>
				</div>
				
			</div>
		</div>

		<script type="text/javascript">
			
			var form = layui.form,
				layer = layui.layer,
				layedit = layui.layedit,
				laydate = layui.laydate;
				form.render();
				
			
			function getMenuList(){
				$.ajax({
					type:"post",
					url:"",
					async:true,
					data:{
						
					},
					success:function(res){
						renderDtree(res)
					},
					error:function(err){
						layer.msg('获取列表出错',{icon:5})
					}
				});
			}
				
				
				
				
			function renderDtree(dataList){
				d = new dTree('d');
				d.add(0,-1,'权限管理');
				for(var i =0;i<dataList.length;i++){
					var pid = dataList[i].id;
					d.add(pid,0,'authority', pid ,dataList[i].cdmc, dataList[i].checked);
					if(dataList[i].children&&dataList[i].children.length){
						for(var j=0;j<dataList[i].children.length;j++){
							var cItem = dataList[i].children[j];
							var cid = cItem.id;
							d.add(cid,pid,'authority', cid, cItem.cdmc,cItem.checked);
						
						}
						
					}
	
				}
				document.write(d);
				d.openAll();
			}
				
				
				
			getMenuList();	
			
			
			function save() {
				var count = 0;
				var obj = document.all.authority;
				var newArr=[];
				for(i = 0; i < obj.length; i++) {
					if(obj[i].checked) {
						newArr.push(obj[i].value);
						count++;
					}
				}
				newArr = String(newArr);
				if(!newArr.length){
					layer.msg('至少选择一个',{icon:5})
					return ;
				}
				$.ajax({
					type:"post",
					url:"",
					async:true,
					data:{
						newArr:newArr
					},
					success:function(res){
						//renderDtree(res)
						location.href="/ss"
					},
					error:function(err){
						layer.msg('保存出错',{icon:5})
					}
				});
			}
			
			
			
			
			
		</script>
	</body>
</html>